<?php
ob_clean();
    $id=empty($_GET['id'])?0:$_GET['id'];

    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
        $sql="select * from `cate` where`pid`=$id ";
        $result=mysqli_query($link,$sql);
        echo ($result->num_rows>0)?1:0;
        die;
    }
    $row=getCateDel($id);
    if($row>0){
        echo '<script>alert("删除成功");location.href="index.php?c=cate&a=list&admin=1";</script>';die;
    }else{
        echo '<script>alert("删除失败");history.go(-1);</script>';die;
    }
    function getCateDel($pid=0){

        $sql="select * from `cate` where`pid`=$pid ";
        //取出数据
        $result=mysqli_query($GLOBALS['link'],$sql);
                //如果还能取出子集则继续循环下去
        if($result->num_rows>0){
            while($arr = mysqli_fetch_assoc($result)){
                getCateDel($arr['id']);
            }
        }
        //如果不能取出子集则执行删除操作

        return del($GLOBALS['c'],$pid);
    }




?>